import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/index'
Vue.use(VueRouter)

const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    meta: { title: '登录' },
    component: () => import('../views/login.vue')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'index',
        meta: { title: '首页' },
        component: () => import('../views/index.vue')
      }
    ]
  },
  {
    path: '/system',
    meta: { title: '系统管理' },
    component: Layout,
    children: [
      {
        path: 'users',
        name: 'users',
        meta: { title: '人员管理' },
        component: () => import('../views/system/users.vue')
      },
      {
        path: 'roles',
        name: 'roles',
        meta: { title: '角色管理' },
        component: () => import('../views/system/roles.vue')
      },
      {
        path: 'menus',
        name: 'menus',
        meta: { title: '菜单管理' },
        component: () => import('../views/system/menus.vue')
      }
    ]
  },
  {
    path: '/nest',
    meta: { title: '嵌套页面' },
    component: Layout,
    children: [
      {
        path: 'nest-child1',
        name: 'nest-child1',
        meta: { title: '二级页面1' },
        component: () => import('../views/nest/nest-child1.vue'),
        children: [
          {
            path: 'nest-item',
            name: 'nest-item',
            meta: { title: '三级页面1' },
            component: () => import('../views/nest/nest-item.vue')
          }
        ]
      },
      {
        path: 'nest-child2',
        name: 'nest-child2',
        meta: { title: '二级页面2' },
        component: () => import('../views/nest/nest-child2.vue')
      }
    ]
  },
  // 一个简单的嵌套路由，重定向
  {
    path: '/userInfo',
    component: Layout,
    redirect: '/userInfo/index',
    children: [
      {
        path: 'index',
        name: 'userInfo',
        meta: { title: '个人信息' },
        component: () => import('../views/userinfo/index.vue')
      }
    ]
  }
]

const router = new VueRouter({
  routes: constantRoutes,
  scrollBehavior: () => ({ y: 0 })
})

export default router
